package com.swf.seed.algorithms.tree;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: CharBuilder <br/>
 * Function: 字符处理类. <br/>
 * Reason: 用于字符的追加和处理. <br/>
 * date: 2015-1-23 上午10:27:54 <br/>
 *
 * @author shenwf10476
 * @version 
 * @since JDK 1.6
 */
public class CharBuilder {
	private List<Character> list = new ArrayList<Character>();
	public CharBuilder() {
	}
	public CharBuilder(String s) {
		for (char c:s.toCharArray()){
			list.add(c);
		}
	}
	
	public int size(){
		return list.size();
	}
	public Character get(int index){
		return list.get(index);
	}
	public void append(char c){
		list.add(c);
	}
	
	public void clear(){
		list.clear();
	}
	public char[] toChars() {
		char[] cs = new char[list.size()];
		 for (int i=0;i<list.size();i++){
			 cs[i] = list.get(i);
		 }
		 return cs;
	}
	
	public Character top(){
		Character c = null;
		if (list.size() != 0){
			c = list.get(0);
		}
		return c;
	}
	public Character pop(){
		Character c = null;
		if (list.size() != 0){
			c = list.get(0);
			list.remove(0);
		}
		return c;
	}
	
	@Override
	public String toString() {
		return new String(toChars());
	}
}
